// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class InferenceAggregation
{
	/// <summary>
	/// <para>
	/// Path to the buckets that contain one set of values to correlate.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("buckets_path")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.BucketsPath? BucketsPath { get; set; }

	/// <summary>
	/// <para>
	/// <c>DecimalFormat</c> pattern for the output value.
	/// If specified, the formatted value is returned in the aggregation’s <c>value_as_string</c> property.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("format")]
	public string? Format { get; set; }

	/// <summary>
	/// <para>
	/// Policy to apply when gaps are found in the data.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("gap_policy")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.GapPolicy? GapPolicy { get; set; }

	/// <summary>
	/// <para>
	/// Contains the inference type and its options.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("inference_config")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfig? InferenceConfig { get; set; }

	/// <summary>
	/// <para>
	/// The ID or alias for the trained model.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("model_id")]
	public Elastic.Clients.Elasticsearch.Serverless.Name ModelId { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(InferenceAggregation inferenceAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.Inference(inferenceAggregation);
}

public sealed partial class InferenceAggregationDescriptor<TDocument> : SerializableDescriptor<InferenceAggregationDescriptor<TDocument>>
{
	internal InferenceAggregationDescriptor(Action<InferenceAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public InferenceAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.BucketsPath? BucketsPathValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.GapPolicy? GapPolicyValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfig? InferenceConfigValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor<TDocument> InferenceConfigDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor<TDocument>> InferenceConfigDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Name ModelIdValue { get; set; }

	/// <summary>
	/// <para>
	/// Path to the buckets that contain one set of values to correlate.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor<TDocument> BucketsPath(Elastic.Clients.Elasticsearch.Serverless.Aggregations.BucketsPath? bucketsPath)
	{
		BucketsPathValue = bucketsPath;
		return Self;
	}

	/// <summary>
	/// <para>
	/// <c>DecimalFormat</c> pattern for the output value.
	/// If specified, the formatted value is returned in the aggregation’s <c>value_as_string</c> property.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor<TDocument> Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Policy to apply when gaps are found in the data.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor<TDocument> GapPolicy(Elastic.Clients.Elasticsearch.Serverless.Aggregations.GapPolicy? gapPolicy)
	{
		GapPolicyValue = gapPolicy;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Contains the inference type and its options.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor<TDocument> InferenceConfig(Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfig? inferenceConfig)
	{
		InferenceConfigDescriptor = null;
		InferenceConfigDescriptorAction = null;
		InferenceConfigValue = inferenceConfig;
		return Self;
	}

	public InferenceAggregationDescriptor<TDocument> InferenceConfig(Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor<TDocument> descriptor)
	{
		InferenceConfigValue = null;
		InferenceConfigDescriptorAction = null;
		InferenceConfigDescriptor = descriptor;
		return Self;
	}

	public InferenceAggregationDescriptor<TDocument> InferenceConfig(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor<TDocument>> configure)
	{
		InferenceConfigValue = null;
		InferenceConfigDescriptor = null;
		InferenceConfigDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The ID or alias for the trained model.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor<TDocument> ModelId(Elastic.Clients.Elasticsearch.Serverless.Name modelId)
	{
		ModelIdValue = modelId;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BucketsPathValue is not null)
		{
			writer.WritePropertyName("buckets_path");
			JsonSerializer.Serialize(writer, BucketsPathValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (GapPolicyValue is not null)
		{
			writer.WritePropertyName("gap_policy");
			JsonSerializer.Serialize(writer, GapPolicyValue, options);
		}

		if (InferenceConfigDescriptor is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, InferenceConfigDescriptor, options);
		}
		else if (InferenceConfigDescriptorAction is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor<TDocument>(InferenceConfigDescriptorAction), options);
		}
		else if (InferenceConfigValue is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, InferenceConfigValue, options);
		}

		writer.WritePropertyName("model_id");
		JsonSerializer.Serialize(writer, ModelIdValue, options);
		writer.WriteEndObject();
	}
}

public sealed partial class InferenceAggregationDescriptor : SerializableDescriptor<InferenceAggregationDescriptor>
{
	internal InferenceAggregationDescriptor(Action<InferenceAggregationDescriptor> configure) => configure.Invoke(this);

	public InferenceAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.BucketsPath? BucketsPathValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.GapPolicy? GapPolicyValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfig? InferenceConfigValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor InferenceConfigDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor> InferenceConfigDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Name ModelIdValue { get; set; }

	/// <summary>
	/// <para>
	/// Path to the buckets that contain one set of values to correlate.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor BucketsPath(Elastic.Clients.Elasticsearch.Serverless.Aggregations.BucketsPath? bucketsPath)
	{
		BucketsPathValue = bucketsPath;
		return Self;
	}

	/// <summary>
	/// <para>
	/// <c>DecimalFormat</c> pattern for the output value.
	/// If specified, the formatted value is returned in the aggregation’s <c>value_as_string</c> property.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Policy to apply when gaps are found in the data.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor GapPolicy(Elastic.Clients.Elasticsearch.Serverless.Aggregations.GapPolicy? gapPolicy)
	{
		GapPolicyValue = gapPolicy;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Contains the inference type and its options.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor InferenceConfig(Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfig? inferenceConfig)
	{
		InferenceConfigDescriptor = null;
		InferenceConfigDescriptorAction = null;
		InferenceConfigValue = inferenceConfig;
		return Self;
	}

	public InferenceAggregationDescriptor InferenceConfig(Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor descriptor)
	{
		InferenceConfigValue = null;
		InferenceConfigDescriptorAction = null;
		InferenceConfigDescriptor = descriptor;
		return Self;
	}

	public InferenceAggregationDescriptor InferenceConfig(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor> configure)
	{
		InferenceConfigValue = null;
		InferenceConfigDescriptor = null;
		InferenceConfigDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The ID or alias for the trained model.
	/// </para>
	/// </summary>
	public InferenceAggregationDescriptor ModelId(Elastic.Clients.Elasticsearch.Serverless.Name modelId)
	{
		ModelIdValue = modelId;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BucketsPathValue is not null)
		{
			writer.WritePropertyName("buckets_path");
			JsonSerializer.Serialize(writer, BucketsPathValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (GapPolicyValue is not null)
		{
			writer.WritePropertyName("gap_policy");
			JsonSerializer.Serialize(writer, GapPolicyValue, options);
		}

		if (InferenceConfigDescriptor is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, InferenceConfigDescriptor, options);
		}
		else if (InferenceConfigDescriptorAction is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.InferenceConfigDescriptor(InferenceConfigDescriptorAction), options);
		}
		else if (InferenceConfigValue is not null)
		{
			writer.WritePropertyName("inference_config");
			JsonSerializer.Serialize(writer, InferenceConfigValue, options);
		}

		writer.WritePropertyName("model_id");
		JsonSerializer.Serialize(writer, ModelIdValue, options);
		writer.WriteEndObject();
	}
}